{% extends 'base.html' %}
{% include 'link_css.html' %}
{% block content %}


<div class="text-center">
<form  class="col-lg-12" action="{% url 'createRepo' %}" method="post" id="submitform">

 <fieldset class="form-group">
    <label for="formGroupExampleInput">运行环境</label>
    <select id="env" class="selectpicker form-control" data-live-search="true" name="env"  onchange="getoption(this.value)">
      <option value="none"></option>
      <option value="1">生产环境</option>
      <option value="2">测试环境</option>
    </select>
 </fieldset>



 <fieldset class="form-group">
    <label for="formGroupExampleInput">部署主机</label>
    <select id="hostname" class="selectpicker form-control" data-live-search="true" name="hostname">
    </select>
 </fieldset>



 <fieldset class="form-group">
    <label for="formGroupExampleInput">svn name</label>
    <input type="text" class="form-control" id="svnName" placeholder="请输入你需要创建的SVN名称" name="svnName" required="" >
  </fieldset>
  <fieldset class="form-group">
    <label for="formGroupExampleInput2">Re-enter svn name</label>
    <input type="text" class="form-control" id="svnNameAgain" placeholder="请再次确认你需要创建的SVN名称" name="svnNameAgain" required="" >
  </fieldset>



    <input  id="sub" class="btn btn-danger" type="submit" value="Deploy" disabled="disabled" >
</form>


<script>
    function getoption(val) {


        var env = document.getElementById("env").value;
        var select = document.getElementById("hostname");



        select.options.length = 0;   // del options
        if (env != "none") {
            $.getJSON("/subversion/getSubversionHost",{"env":env},function (result) {
                //console.log(result)

                for (i=0;i<result.length;i++) {
                    var objOption = document.createElement("OPTION")
                    objOption.value = result[i]
                    objOption.text = result[i]
                    select.add(objOption)
                }
                if (result.length != 0) {
                    $("#sub").attr("disabled", false)
                }
                else{
                    $("#sub").attr("disabled", true)
                }
                console.log(result.length)
                //alert('Please enter the correct svnName,try again....')
            })
        }
        else{
            $("#sub").attr("disabled", true)
        }
    }




    $("#submitform").on("submit",function(e){
        var svnName = document.getElementById("svnName").value;
        var svnNameAgain = document.getElementById("svnNameAgain").value;
        if (svnName != svnNameAgain) {
            alert('Please enter the correct svnName,try again....')
            return false
        }
    })
</script>
{% endblock %}
